

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:dots_indicator/dots_indicator.dart';

class SwitchWidget extends StatefulWidget {
  const SwitchWidget({super.key});

  @override
  State<SwitchWidget> createState() => _SwitchWidgetState();
}

class _SwitchWidgetState extends State<SwitchWidget> {
    int _selectedIndex = 0;
    final _pageCount = 5; // Total number of pages

    void _onPageChanged(int index) {
      setState(() {
        _selectedIndex = index % _pageCount;
      });
    }

    @override
    Widget build(BuildContext context) {
      return Container(
          padding: const EdgeInsets.all(8),
          height: 200,
          child: Column(
            children: <Widget>[
              Expanded(
                child:CarouselSlider(
                    options: CarouselOptions(
                      height: 150.0,
                      autoPlay: true,
                      enlargeCenterPage: true,
                      onPageChanged: (index, reason) => _onPageChanged(index),
                      ),
                    items: [1, 2, 3, 4, 5].map((i) {
                      return Builder(
                        builder: (BuildContext context) {
                          return Container(
                            width: MediaQuery.of(context).size.width,
                            margin: const EdgeInsets.symmetric(horizontal: 5.0),
                            decoration: const BoxDecoration(color: Colors.amber),
                            child: Text(
                              'text $i',
                              style: const TextStyle(fontSize: 16.0),
                            ),
                          );
                        },
                      );
                    }).toList(),
                  )
              ),
              DotsIndicator(
                dotsCount: _pageCount,
                position: _selectedIndex.toDouble(),
                decorator: const DotsDecorator(
                  activeColor: Colors.blue,
                ),
              ),
            ],
      )
    );
  }
}


